package poker;

import java.util.ArrayList;

import exception.HandSizeEx;
import exception.InvalidCardEx;

public abstract class Player {
	
	protected String name;
	protected int tokens;
	protected int bet;
	protected int wins;
	protected boolean hasFolded;
	protected boolean allIn;
	protected boolean disconnected;
	protected boolean broken=false;
	protected ArrayList<Card> hand;
	
	public void receiveCard(short c) throws InvalidCardEx, HandSizeEx {
		if (hand.size() < 5) {
			hand.add(new Card(c));
		} else
			throw new HandSizeEx();
	}
	
	public abstract boolean isBot();
	
	public boolean hasFolded() {
		return hasFolded;
	}
	
	public boolean hasAllIn() {
		return allIn;
	}
	
	public boolean hasDCed() {
		return disconnected;
	}
	
	public boolean isBroken() {
		return broken;
	}
	
	public abstract PlayerAction takeTurn(Phase phase, int bet, boolean allIn) throws HandSizeEx;
	
	public abstract void exchangeCards(int cards[]);
	
	public void pay(int amount) {
		tokens -= amount;
	}
	
	public abstract void endTurn() throws HandSizeEx;
	
	public abstract void printCards(int i) throws HandSizeEx;

	public int getHandSize() {
		return hand.size();
	}

	public int reportCards(int[] report) {
		for(int i=0; i < report.length; i++) {
			report[i] = hand.get(i).getCard();
		}
		return 0;
	}
	
	public String getName() {
		return name;
	}
	
	public int getTokens() {
		return tokens;
	}
	
	public int getBet() {
		return bet;
	}
	
	public void setBet(int bet) {
		this.bet = bet;
	}
	
	public int getWins() {
		return wins;
	}
	
	public void dropHand() {
		for(int i=4; i>-1; i--) {
			hand.remove(i);
		}
		hasFolded = false;
		bet = 0;
	}
	
	public void win() {
		wins++;
	}
	
	public void fold() {
		hasFolded = true;
	}
	
	public void allIn() {
		allIn = true;
	}
	
	public void dc() {
		disconnected = true;
	}
	
	public void bankrupt() {
		broken = true;
	}
}
